package com.bw.controller;

import com.bw.bean.Student;
import com.bw.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

//@Controller + @ResponseBody ==> @RestController
@RestController
public class StudentController {
    @Autowired
    StudentService studentService;

    @PostMapping("/findAll")
//    @ResponseBody
    public Student findAll(){
        for (Student student : studentService.findAll()) {
            System.out.println(student);
            return student;
        }
        return null;
    }

    @GetMapping("/findAll1")
//    @ResponseBody
    public Student findAll1(){
        for (Student student : studentService.findAll()) {
            System.out.println(student);
            return student;
        }
        return null;
    }


    @RequestMapping("/findAll2")
//    @ResponseBody
    public Student findAll2(){
        for (Student student : studentService.findAll()) {
            System.out.println(student);
            return student;
        }
        return null;
    }

    @RequestMapping("/findLike")
    public Student findLike(String sname){
        for (Student student : studentService.findLike(sname)) {
            return  student;

        }
        return null;
    }
}
